package com.cff.action;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Properties;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.text.JTextComponent;

import com.cff.common.Constant;
import com.cff.common.SimpleFrame;
import com.cff.util.EventUtil;
import com.cff.util.FileUtil;
import com.cff.util.SignTools;

public class CommonKeyValueActionListener implements ActionListener {
	
	private String KeyType;
	private static Properties confPro = null;

	public CommonKeyValueActionListener(String KeyType) {
		super();
		this.KeyType = KeyType;
	}


	@Override
	public void actionPerformed(ActionEvent e) {
		confPro = FileUtil.getInstance();

		String keyDesc = "";
		String key = "";
		String buttonDesc = "";
		if(Constant.BOXVERIFY.equals(KeyType)){
			key = "";
			keyDesc = "密码：";
			buttonDesc = "验证";
		}
		
		JFrame tmpFrame = new JFrame();
		tmpFrame.setBounds(200, 200, 600, 300);
		tmpFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		tmpFrame.setLayout(null);
		
		JLabel dataLabel = new JLabel();
		dataLabel.setBounds(20, 20, 100, 50);
		dataLabel.setText("用户：");
		
		JTextArea dataText = new JTextArea();
		dataText.setBounds(130, 35, 350, 50);
		dataText.setSelectedTextColor(Color.RED);
		dataText.setLineWrap(true);        //激活自动换行功能 
		dataText.setWrapStyleWord(true);            // 激活断行不断字功能
		dataText.setText(confPro.getProperty("user"));
		
		JLabel keyLabel = new JLabel();
		keyLabel.setBounds(20, 105, 100, 50);
		keyLabel.setText(keyDesc);
		
		JTextArea keyText = new JTextArea();
		keyText.setBounds(130, 105, 350, 50);
		keyText.setText(key);
		keyText.setSelectedTextColor(Color.RED);
		keyText.setLineWrap(true);        //激活自动换行功能 
		keyText.setWrapStyleWord(true);            // 激活断行不断字功能
		keyText.setText(confPro.getProperty("passwd"));

		JButton okButton = new JButton(buttonDesc); 
		okButton.setBounds(tmpFrame.getWidth()/2-50, tmpFrame.getHeight()-80, 70, 30);
		
		tmpFrame.add(dataLabel);
		tmpFrame.add(dataText);
		tmpFrame.add(keyLabel);
		tmpFrame.add(keyText);
		
		tmpFrame.add(okButton);
		ActionListener boxVerifyActionListener = new BoxVerifyActionListener(KeyType, tmpFrame,dataText,keyText);
		EventUtil.putEvent(okButton, boxVerifyActionListener);
		tmpFrame.setVisible(true);
		
	}

}
